/*
 * Postmore - a pop3 supported mailing list server;
 * Copyright (C) 2010 Peng Lei, pyp125@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 *
 * You should have received a copy of the GNU Public License along with this
 * program. If not, see http://www.gnu.org/licenses/.
 */
/* pm.exe - individual configuration executive. */
#ifndef _PM_EXE_H

#define _PM_EXE_H

#define PMEXEVERSION "pm.exe version: 0.1 beta. Build: %s\n"

#define MAILMAX 40960 
#define BUFMAX 1024
#define CMDMAX 256
#define PATHMAX 255
#define LINEMAX 512

#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>

#include "utilities.h"

/* The struct below is used to authorization; */
typedef struct _auth_bundle
{
	char at_name[128];	/* The server's name; */
	char at_mail[128];	/* The email address; */
	char at_hostname[128];	/* The server's hostname; */
	char at_address[16];	/* The server's IP address; */
	int  at_port;	/* The number of port which is used to communication; */
	char at_username[64]; /* Username; */
	char at_password[64]; /* Password; */
	char at_username_base64[96];	/* Username, after base64; */
	char at_password_base64[96];	/* Password, after base64; */
} ATBD;
/* Initalized an authorization bundle; */
int init_atbd(ATBD* info, const char* name, const char* mail, const char* hostname, int port, const char* username, const char* password);
/* Show usage; */
void usage();
/* TCP Socket functions; */
int tcp_init(int* st);
int tcp_connect(int st, ATBD* info);
int tcp_bind(int st, int port);
int tcp_send(int st, void* buffer);
int tcp_recv(int st, void* buffer, size_t size);
int tcp_close(int st);
/* POP3 process; */
void pop3_process(ATBD* info, int pout, int tsleep);
/* SMTP process; */
void smtp_process(ATBD* info, int pin);
/* SIGKILL performance; */
void sigkill_perform(int signum);
/* Mail operations; */
char _m_file[255];
int mail_init(const char* p);
int mail_get(int* n, int* s);
int mail_set(int n, int s);
/* Subscription operations; */
char _s_file[255];
int sub_init(const char* p);
/* Note: this function will overwrite the data of slist; */
NODE* sub_get();
/* Make a sub node from a string; */
NODE* sub_make(const char* p);
int sub_add(NODE* slist, const char* s);
int sub_del(NODE* slist, const char* s);
int sub_write(NODE* slist);
/* Sub state; If no subscriber, set it to 1, otherwise it equals 0; */
int _no_sub;

#endif
